package la.iok.hzsvn.lewin.movie.shopmovie.controller;

import la.iok.hzsvn.lewin.movie.core.RoleEnum;
import la.iok.hzsvn.lewin.movie.core.Token;
import la.iok.hzsvn.lewin.movie.core.exception.ErrorCode;
import la.iok.hzsvn.lewin.movie.shopmovie.model.ShopPlayerVo;
import la.iok.hzsvn.lewin.movie.shopmovie.service.ShopPlayerService;
import la.iok.hzsvn.lewin.mybatis.model.PageParam;
import la.iok.hzsvn.lewin.mybatis.model.PageVo;
import la.iok.hzsvn.lewin.mybatis.model.SortParam;
import la.iok.hzsvn.share.response.OperatorResponse;
import la.iok.hzsvn.share.response.OperatorResponses;
import la.iok.hzsvn.share.response.SingleDataResponse;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("shopPlayers")
public class ShopPlayerController {
    private final ShopPlayerService shopPlayerService;

    public ShopPlayerController(ShopPlayerService shopPlayerService) {
        this.shopPlayerService = shopPlayerService;
    }

    @GetMapping
    public SingleDataResponse<PageVo<ShopPlayerVo>> page(@RequestHeader Token token, PageParam pageParam, SortParam sortParam,
                                                         String phoneNumber, String nickname, String text){
        return new SingleDataResponse<>(shopPlayerService.page(token, pageParam, sortParam, phoneNumber, nickname, text));
    }

    @PutMapping("Save/{id}/{orgUnitId}")
    public OperatorResponse SaveShopPlayer(@RequestHeader Token token, @PathVariable Long id, @PathVariable Long orgUnitId)
    {
        ErrorCode.ORG_UNIT_ACCESS_DENIED.assertTrue(token.hasAnyAuthority
                (RoleEnum.Manager, RoleEnum.ShopManager, RoleEnum.CarpoolMaster, RoleEnum.CustomerService),"权限","权限不足");
        Long playerid=shopPlayerService.save(id,orgUnitId);
        ErrorCode.INVALID_USER.assertNotNull(playerid);
        return OperatorResponses.success();
    }
}
